package com.paw.portal.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.paw.common.domain.Result;
import com.paw.portal.entity.SysRoleMenu;
import com.paw.portal.entity.SysUserRole;
import com.paw.portal.service.IAntdRoleService;
import com.paw.portal.service.ISysRoleMenuService;
import com.paw.portal.service.ISysRoleService;
import com.paw.portal.service.ISysUserRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Rubble
 * @date 2021/8/28
 **/
@Slf4j
@Service
public class AntdRoleServiceImpl implements IAntdRoleService {

  @Autowired
  private ISysRoleService sysRoleService;

  @Autowired
  private ISysRoleMenuService sysRoleMenuService;

  @Autowired
  private ISysUserRoleService sysUserRoleService;

  @Override
  @Transactional(rollbackFor = Exception.class)
  public Result<Boolean> delRoleWithMenu (Long id) {

    boolean flag = sysRoleService.removeById(id);
    // 删除角色菜单
    sysRoleMenuService.remove(Wrappers.<SysRoleMenu>lambdaQuery().eq(SysRoleMenu::getRoleId,id));
    // 删除用户角色
    sysUserRoleService.remove(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getRoleId,id));

    return Result.success(flag);
  }
}
